package model.action;

import java.util.Date;
import java.util.List;

import model.dao.BaiDAO;
import model.entities.Category;
import model.entities.Post;
import model.entities.User;

import com.opensymphony.xwork2.ActionSupport;

public class PostAndCommentAction extends ActionSupport {
    private String ten;
    private String noi_dung;
    private int category_id;
    private BaiDAO baiDAO;
    private List<Post> listAllPost;
    public PostAndCommentAction() {
        baiDAO = new BaiDAO();
    }
    public String createNewPost() {
        //create new post
        User curUser = baiDAO.getUserByID(1);
        Category category = baiDAO.getCategoryByID(1);
        Date date = new Date();
        Post newPost = new Post(curUser,category,ten,noi_dung, date);
        System.out.println(ten);
        System.out.println(noi_dung);
        boolean result = baiDAO.newPost(newPost);
        if (result) {
            return SUCCESS;
        } else {
            return ERROR;
        }
        
    }   
    public String allPost() {
        listAllPost = baiDAO.getAllPost();
        return SUCCESS;
    }
    public String getTen() {
        return ten;
    }
    public void setTen(String ten) {
        this.ten = ten;
    }
    public String getNoi_dung() {
        return noi_dung;
    }
    public void setNoi_dung(String noi_dung) {
        this.noi_dung = noi_dung;
    }
    public int getCategory_id() {
        return category_id;
    }
    public void setCategory_id(int category_id) {
        this.category_id = category_id;
    }
    public BaiDAO getBaiDAO() {
        return baiDAO;
    }
    public void setBaiDAO(BaiDAO baiDAO) {
        this.baiDAO = baiDAO;
    }
    public List<Post> getListAllPost() {
        return listAllPost;
    }
    public void setListAllPost(List<Post> listAllPost) {
        this.listAllPost = listAllPost;
    }
    
    
    
}
